package java6681.lesson04;

import java.util.Arrays;
import java.util.Scanner;
//数组排序 输出存在的值在数组的第几个
public class ArraySortAndSearch6681 {
    public static void main(String[] args) {
        int[] arr = {41,31,22,18,71,23,19,43,59};
        System.out.println(Arrays.toString(arr));
        System.out.println("排序后的数组：");
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        System.out.print("请输入要查找的元素：");
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int index = Arrays.binarySearch(arr,num);
        if (index == num){
            System.out.println(num + "是数组中的第" + (index) + "个元素");
        }else{
            System.out.println(index+1);
        }

    }
}
